package cn.com.api.mapper;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import cn.com.api.entity.ApiU_discover;
import cn.com.api.mapper.base.U_discoverMapperBase;
import cn.com.util.PageInfo;

//DAO
public interface ApiU_discoverMapper extends U_discoverMapperBase {

	// 新增对象后返回记录ID
	public int U_discoverInsertion(ApiU_discover u_discover);

	@Delete("DELETE FROM U_DISCOVER WHRER ID = #{id}")
	public int U_discoverdelete(Integer id);

	@Update("UPDATE U_DISCOVER SET VERIFY_TIME = str_to_date(#{verify_time,jdbcType=VARCHAR},'yyyy-mm-dd hh24:mi:ss'), VERIFY_BY = #{verify_by}, IS_VERIFY = #{is_verify}  WHERE ID = #{id}")
	public int U_discoverVerify(ApiU_discover u_discover);

	@Select("SELECT * FROM U_DISCOVER  WHERE USER_ID = #{userId}")
	public List<ApiU_discover> getU_discoverByUser(String userId);

	@Select("SELECT A.*, C.CATE_NAME FROM U_DISCOVER A LEFT JOIN U_DISCOVER_CATE C ON A.ACTIVITY_TYPE=C.ID WHERE A.IS_DELETE=0 AND A.IS_CANCEL=0 AND A.IS_VERIFY=1 AND now() BETWEEN str_to_date(A.BEGIN_TIME,'yyyy-mm-dd hh24:mi:ss') AND str_to_date(A.END_TIME,'yyyy-mm-dd hh24:mi:ss') AND (A.TITLE like '%' || #{label} || '%' OR C.CATE_NAME LIKE '%' || #{label} || '%') AND A.TYPE=#{type}")
	public List<ApiU_discover> getU_discoverByUserLabels(@Param("label") String label, @Param("type") Integer type);

	// 删除
	@Update("UPDATE　U_DISCOVER SET IS_DELETE = 1 WHERE ID = #{id} ")
	public int U_discover_delete(Integer id);

	// 取消
	@Update("UPDATE　U_DISCOVER SET IS_CANCEL = 1 WHERE ID = #{id} ")
	public int U_discovercancel(Integer id);

	// 修改
	@Update("UPDATE U_DISCOVER SET HEAD_IMG = #{head_img}, VEDIO = #{vedio}, TITLE = #{title}, BEGIN_TIME = #{begin_time}, END_TIME = #{end_time}, CITY = #{city,jdbcType=VARCHAR}, ADDRESS = #{address}, PEOPLE_LIMIT = #{people_limit}, DESCRIPTION = #{description}, ACTIVITY_TYPE = #{activity_type}, LONGITUDE = #{longitude}, LATITUDE = #{latitude}, IS_VERIFY = #{is_verify}, USER_ID = #{user_id}, ADD_TIME = str_to_date(#{add_time,jdbcType=VARCHAR},'yyyy-mm-dd hh24:mi:ss'), VERIFY_TIME = str_to_date(#{verify_time,jdbcType=VARCHAR},'yyyy-mm-dd hh24:mi:ss'), VERIFY_BY = #{verify_by}, AVERAGE_PRICE = #{average_price,jdbcType=NUMERIC}, IS_REFUND = #{is_refund,jdbcType=NUMERIC}, IS_ADD = #{is_add,jdbcType=NUMERIC}, TYPE = #{type,jdbcType=NUMERIC}, share_count = #{share_count,jdbcType=NUMERIC} WHERE ID = #{id,jdbcType=NUMERIC}")
	public int update_discover(ApiU_discover u_discover);

	// 修改
	@Update("UPDATE U_DISCOVER SET HEAD_IMG = #{head_img,jdbcType=VARCHAR}, VEDIO = #{vedio,jdbcType=VARCHAR}, TITLE = #{title,jdbcType=VARCHAR}, BEGIN_TIME = #{begin_time,jdbcType=VARCHAR}, END_TIME = #{end_time,jdbcType=VARCHAR}, CITY = #{city,jdbcType=VARCHAR}, ADDRESS = #{address,jdbcType=VARCHAR}, PEOPLE_LIMIT = #{people_limit,jdbcType=VARCHAR}, DESCRIPTION = #{description,jdbcType=VARCHAR}, ACTIVITY_TYPE = #{activity_type,jdbcType=VARCHAR}, LONGITUDE = #{longitude,jdbcType=VARCHAR}, LATITUDE = #{latitude,jdbcType=VARCHAR}, IS_VERIFY = #{is_verify,jdbcType=VARCHAR}, USER_ID = #{user_id,jdbcType=VARCHAR}, ADD_TIME = str_to_date(#{add_time,jdbcType=VARCHAR},'yyyy-mm-dd hh24:mi:ss'), VERIFY_TIME = str_to_date(#{verify_time,jdbcType=VARCHAR},'yyyy-mm-dd hh24:mi:ss'), VERIFY_BY = #{verify_by,jdbcType=VARCHAR}, AVERAGE_PRICE = #{average_price,jdbcType=NUMERIC}, IS_REFUND = #{is_refund,jdbcType=NUMERIC}, IS_ADD = #{is_add,jdbcType=NUMERIC}, TYPE = #{type,jdbcType=NUMERIC}, share_count = #{share_count,jdbcType=NUMERIC} WHERE ID = #{id,jdbcType=NUMERIC}")
	public int update_discover_info(ApiU_discover u_discover);

	// 展会信息列表
	public List<ApiU_discover> find_discover_exhibition(@Param("map") Map<String, Object> params,
			@Param("page") PageInfo pageInfo);

	public List<ApiU_discover> getU_discoverByJoinUser(@Param("map") Map<String, Object> params);

	@Update("update u_discover set SHARE_COUNT = nvl(SHARE_COUNT,0) + 1 where id = #{discover_id}")
	public void insertU_discoverShare(Map<String, String> paramMap);

	public ApiU_discover findU_discovers_detail(Map<String, String> params);

	public List<ApiU_discover> find_discover_list(@Param("map") Map<String, Object> params,
			@Param("page") PageInfo pageInfo);

	public int find_discover_join_count(Map<String, Object> params);

	public int find_discover_publish_count(Map<String, Object> params);

	public List<ApiU_discover> findFavoriteDiscoverListPage(@Param("cate_type") String cate_type,
			@Param("user_id") String user_id, @Param("type") Integer type, @Param("page") PageInfo page);

	public List<ApiU_discover> search_discover_info(@Param("map") Map<String, Object> conditions,
			@Param("page") PageInfo pageInfo);

	public List<Map<String, Object>> find_discover_by_loc_need(@Param("map") Map<String, Object> params);

	public List<Map<String, Object>> find_discover_by_loc_service(@Param("map") Map<String, Object> params);

	public List<Map<String, String>> selectByOrListPage(@Param("map") Map<String, Object> cond,
			@Param("page") PageInfo page);

	public int findU_discovers_status_byUserid(@Param("map") Map<String, String> params);

	public Map<String, Object> getdescription(@Param("map") Map<String, String> params);

	@Select("select d.id, d.type, c.cate_name,c.type as cate_type,d.title from u_discover d left join u_discover_cate c on d.activity_type = c.id where d.id = #{map.id}")
	public Map<String, Object> findTaskInfo(@Param("map") Map<String, Object> param);

	@Select("select distinct d.user_id from u_discover d left join u_discover_cate c on d.activity_type = c.id where  d.type = #{map.type} and c.cate_name = #{map.cate_name} and d.user_id in (select c_id as user_id from t_member where is_take ='1')")
	public List<Map<String, Object>> findToTaskInfo(@Param("map") Map<String, Object> param);

}
